@import org.apache.predictionio.data.storage.EvaluationInstance
@import org.apache.predictionio.tools.dashboard.DashboardConfig
@import org.joda.time.DateTime
@import org.joda.time.format.DateTimeFormat
@(dc: DashboardConfig,
  dashboardStartTime: DateTime,
  env: Map[String, String],
  completedInstances: Seq[EvaluationInstance])
<!DOCTYPE html>
<!--
  Licensed to the Apache Software Foundation (ASF) under one or more
  contributor license agreements.  See the NOTICE file distributed with
  this work for additional information regarding copyright ownership.
  The ASF licenses this file to You under the Apache License, Version 2.0
  (the "License"); you may not use this file except in compliance with
  the License.  You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
-->
<html lang="en">
  <head>
    <title>PredictionIO Dashboard at @{dc.ip}:@{dc.port}</title>
    <link href="/assets/favicon.png" rel="shortcut icon" />
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
    <style type="text/css">
    .string { color: green; }
    .number { color: darkorange; }
    .boolean { color: blue; }
    .null { color: magenta; }
    .key { color: red; }
    </style>
    <script type="text/javascript">
      function syntaxHighlight(json) {
        if (typeof json != 'string') {
          json = JSON.stringify(json, undefined, 2);
        }
        json = json.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
        return json.replace(/("(\\u[a-zA-Z0-9]{4}|\\[^u]|[^\\"])*"(\s*:)?|\b(true|false|null)\b|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?)/g, function (match) {
          var cls = 'number';
          if (/^"/.test(match)) {
            if (/:$/.test(match)) {
              cls = 'key';
            } else {
              cls = 'string';
            }
          } else if (/true|false/.test(match)) {
            cls = 'boolean';
          } else if (/null/.test(match)) {
            cls = 'null';
          }
          return '<span class="' + cls + '">' + match + '</span>';
        });
      }
      function shorternClassName(className) {
        return className.replace(/(\w)\w*\./g, "$1."); 
      }
    </script>
  </head>
  <body>
    <div class="container-fluid">
      <div class="page-header">
        <h1>PredictionIO Dashboard at @{dc.ip}:@{dc.port}</h1>
        <p class="lead">Started on: @{DateTimeFormat.forStyle("FF").print(dashboardStartTime)}</p>
      </div>
      <h2>Completed Evaluations</h2>
      <table class="table table-bordered table-striped">
        <tr>
          <th></th>
          <th>Evaluator Result (One-liner)</th>
          <th>Evaluation Class</th>
          <th>Engine Parameters Generator Class</th>
          <th>Start Time</th>
          <th>End Time</th>
          <th>Batch</th>
        </tr>
        @for(i <- completedInstances) {
        <tr>
          <td>
            <div>
              <a href="/engine_instances/@{i.id}/evaluator_results.html" class="btn btn-primary">HTML</a>
            </div>
          </td>
          <td>
            <div>@{i.evaluatorResults}</div>
          </td>
          <td>
            <span title="@{i.evaluationClass}"><script type="text/javascript">document.write(shorternClassName("@{i.evaluationClass}"));</script></span>
          </td>
          <td>
            <span title="@{i.engineParamsGeneratorClass}"><script type="text/javascript">document.write(shorternClassName("@{i.engineParamsGeneratorClass}"));</script></span>
          </td>
          <td>@{DateTimeFormat.forStyle("MM").print(i.startTime)}</td>
          <td>@{DateTimeFormat.forStyle("MM").print(i.endTime)}</td>
          <td>@{i.batch}</td>
        </tr>
        }
      </table>
      <h2>Environment</h2>
      <p>The following values are accurate up to the time when the dashboard was launched.</p>
      <table class="table table-bordered table-striped">
        @for(k <- env.keys.toSeq.sorted) {
        <tr><th>@{k}</th><td>@{env(k)}</td></tr>
        }
      </table>
    </div>
    <script src="https://code.jquery.com/jquery-1.12.4.min.js" integrity="sha256-ZosEbRLbNQzLpnKIkEdrPv7lOy9C27hHQ+Xp8a4MxAQ=" crossorigin="anonymous"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
  </body>
</html>
